Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codemirror/state

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/state

Editor state data structures for the CodeMirror code editor

  • 6.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is @codemirror/state?

The @codemirror/state package is part of the CodeMirror (version 6) ecosystem, which provides a flexible, extensible text editor. This particular package is responsible for managing the state of the editor, including the document content, selection, and any other state that plugins might add. It allows for the creation, modification, and querying of editor state, facilitating complex text editing features.

What are @codemirror/state's main functionalities?

Creating an Editor State

This feature allows for the initialization of an editor state with a starting document. The document can be a string or a more complex structure for representing text.

{
  import {EditorState} from '@codemirror/state';
  const state = EditorState.create({doc: 'Hello, world!'});
}

Updating the State

This demonstrates how to update the state by creating a transaction. In this example, the text 'Hello' is replaced with 'Goodbye'. Transactions can include changes to the document, selections, and other state aspects.

{
  import {EditorState, Transaction} from '@codemirror/state';
  let newState = state.update({changes: {from: 0, to: 5, insert: 'Goodbye'}}).state;
}

Reading the State

This feature is about accessing the current content of the editor. It shows how to convert the document in the state to a string, which can be useful for saving the content or displaying it elsewhere.

{
  import {EditorState} from '@codemirror/state';
  const content = state.doc.toString();
}

Other packages similar to @codemirror/state

Keywords

FAQs

Package last updated on 19 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc